﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MemoryFormDeal
{
    public partial class DelForm : Form
    {
        private List<ProgramSave> save;
        public DelForm(List<ProgramSave> psave)
        {
            save = psave;
            InitializeComponent();
            ListViewItem item = new ListViewItem();
            for (int i = 0; i < save.Count; i++)
            {
                item = DellistView.Items.Add(Convert.ToString(save[i].No));
                item.SubItems.Add(save[i].PName);
                item.SubItems.Add(Convert.ToString(save[i].PMUse)+"KB");
                item.SubItems.Add(save[i].colour);
                item.SubItems.Add(Convert.ToString(save[i].startunit));
                switch (save[i].pType)
                {
                    case 0:
                        item.SubItems.Add("首次适应");
                        break;
                    case 1:
                        item.SubItems.Add("循环适应");
                        break;
                    default:
                        item.SubItems.Add("Unknown");
                        break;
                }
            }
        }

        private void DelCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void DelOk_Click(object sender, EventArgs e)
        {
            if (DellistView.SelectedItems.Count == 0)
                return;
            ProgramSave temp = new ProgramSave();
            temp.No = Convert.ToInt32(DellistView.FocusedItem.SubItems[0].Text);
            temp.PName = DellistView.FocusedItem.SubItems[2].Text;
            temp.startunit = Convert.ToInt32(DellistView.FocusedItem.SubItems[4].Text);

            InitForm lform1 = (InitForm)this.Owner;
            lform1.GetReturnInfo(temp);
            this.Close();
            lform1.DelP();
        }
    }
}
